package com.xdxc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xdxc.model.entity.ExamPaper;
import com.xdxc.response.Result;
import com.xdxc.service.ExamPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam-paper")
public class ExamPaperController {
    @Autowired
    private ExamPaperService examPaperService;

    @GetMapping("/exam-paper-list")
    public Result listExamPaper(
            @RequestParam(defaultValue = "1") int page, // 页码，默认为1
            @RequestParam(defaultValue = "8") int pageSize) // 每页条数，默认为5)
   {
       Page<ExamPaper> examPaperPage = new Page<>(page, pageSize);
       IPage<ExamPaper> pagedExamPaper =  examPaperService.page(examPaperPage);

       List<ExamPaper> examPapers = pagedExamPaper.getRecords();
       Result result= Result.success(examPapers);
       result.add("totalPage",pagedExamPaper.getTotal());
       result.add("currentPage",pagedExamPaper.getCurrent());
       result.add("pageSize",pagedExamPaper.getSize());
        return result;
    }

    @GetMapping("/paper-exam/{id}")
    public Result getExamPaper(@PathVariable Long id)
    {
     ExamPaper examPaper=   examPaperService.getById(id);
     if (examPaper==null){
         return Result.error("空");
     }
        return Result.success(examPaper);
    }


}
